<?php

	class RRouter
	{
		var $tmp;
		function __construct()
		{
			
		}
		
		function route()
		{
			$user = RUser::getUser();
			$uri = $this->parse();
			
			define('BPM', BP.DS.'modules/mod_'.$uri['module']);
			
			$template = RTemplate::getTemplate($uri['module']);
			
			$hndl = asmpth(BPM, 'mod_'.$uri['module'].'.php');
			
			RImportP($hndl, $uri);
			
			$template->render();	
		}
		
		function parse()
		{
			static $uri;
			
			if ($uri) return $uri;
			
			$path = explode('/', $_SERVER['REQUEST_URI']);
			
			$uri = array();
			$uri['module'] = $path[1]?$path[1]:'index';
			$uri['action'] = $path[2]?$path[2]:'default';
			$c = count($path) - 1;
			for($i = 3; $i < $c; $i)
				$uri[$path[$i]] = $path[++$i];
				
			return $uri;
		}
	}